<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
	<% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":"
		+ request.getServerPort() + path + "/" ; %>

		<!DOCTYPE html>
		<html>

		<head>
			<base href="<%=basePath%>">

			<title>定时任务</title>

			<meta http-equiv="pragma" content="no-cache">
			<meta http-equiv="cache-control" content="no-cache">
			<meta http-equiv="expires" content="0">
			<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
			<meta http-equiv="description" content="This is my page">
			<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

		</head>

		<body>
			<%@ include file="/WEB-INF/jsp/common/header.jsp" %>
				<%@ include file="/WEB-INF/jsp/common/loadDiv.jsp" %>

					<script type="text/javascript">
						$(function () {
							bindgrid();
						});

					</script>
					<script>
						function del(node) {
							$.ajax({
								type: "delete",
								url: 'schedule/job/delete?id=' + node.jobId,
								//                dataType: "xml",				
								success: function (data) {
									$.messager.alert('消息', data.msg);
									selectList();
								},
								error: function (XMLHttpRequest, textStatus, errorThrown) {
									$.messager.alert('消息', errorThrown);
								}
							});
						}
						function run(node) {
							$.ajax({
								type: "post",
								url: 'schedule/job/run?id=' + node.jobId,
								//                dataType: "xml",				
								success: function (data) {
									$.messager.alert('消息', data.msg);
									selectList();
								},
								error: function (XMLHttpRequest, textStatus, errorThrown) {
									$.messager.alert('消息', errorThrown);
								}
							});
						}
						function pause(node) {
							$.ajax({
								type: "post",
								url: 'schedule/job/pause?id=' + node.jobId,
								dataType: "json",
								data: JSON.stringify(node),
								contentType: "application/json",
								success: function (data) {
									$.messager.alert('消息', data.msg);
									selectList();
								},
								error: function (XMLHttpRequest, textStatus, errorThrown) {
									$.messager.alert('消息', errorThrown);
								}
							});
						}
						function resume(node) {
							$.ajax({
								type: "post",
								url: 'schedule/job/resume?id=' + node.jobId,
								dataType: "json",
								data: JSON.stringify(node),
								contentType: "application/json",
								success: function (data) {
									$.messager.alert('消息', data.msg);
									selectList();
								},
								error: function (XMLHttpRequest, textStatus, errorThrown) {
									$.messager.alert('消息', errorThrown);
								}
							});
						}

						function save() {
							var node = {
								jobId: $('#jobId').val(),
								beanName: $('#beanName').textbox('getValue'),
								methodName: $('#methodName').textbox('getValue'),
								cronExpression: $('#cronExpression').textbox('getValue'),
								status: $('#status').combobox('getValue'),
								remark: $('#remark').textbox('getValue')
							}
							$.ajax({
								type: "post",
								url: 'schedule/job/save',
								dataType: "json",
								data: JSON.stringify(node),
								contentType: "application/json",
								success: function (data) {
									$.messager.alert('消息', data.msg); selectList();
								},
								error: function (XMLHttpRequest, textStatus, errorThrown) {
									$.messager.alert('消息', errorThrown);
								}
							});

						}

						function editrow() {
							//编辑用户
							var row = $('#dg').datagrid('getSelected');
							if (row) {
								$('#add').window('open');
								$('#fm').form('load', row);
								$('#status').combobox('setValue', row.status);

							} else {
								$.messager.alert('消息', '请选中一个用户');
							}
						}
						function selectList() {
							let dg = $('#dg');
							dg.datagrid('enableFilter');
							dg.datagrid('load');

						}
					</script>
					<script>
						function bindgrid() {
							$('#dg').datagrid(
								{
									title: '任务列表',
									url: "schedule/job/selectList",
									iconCls: 'icon-application',
									width: getWidth(0.98),
									height: 415,
									nowrap: true,
									rownumbers: true,
									animate: false,
									collapsible: false,
									clientPaging: false,
									filterDelay: 0,
									remoteFilter: true,
									singleSelect: true,
									pagination: true,
									remoteSort: true,
									columns: [[{
										field: 'jobId',
										title: '任务id',
										sortable: true,
										formatter: function (val, rec) {
											return val ? unescape(val) : '';
										}
									}, {
										field: 'beanName',
										title: '执行类',
										sortable: true,
										formatter: function (val, rec) {
											return val ? unescape(val) : '';
										}
									}, {
										field: 'methodName',
										title: '执行方法',
										sortable: true,
										formatter: function (val, rec) {
											return val ? unescape(val) : '';
										}
									}, {
										field: 'params',
										title: '参数',
										sortable: true,
										formatter: function (val, rec) {
											return val ? unescape(val) : '';
										}
									}, {
										field: 'cronExpression',
										title: '表达式',
										sortable: true,
										formatter: function (val, rec) {
											return val ? unescape(val) : '';
										}
									}, {
										field: 'status',
										title: '启用禁用',
										sortable: true,
										formatter: function (val, rec) {
											return val == '1' ? '启用' : '禁用';
										}
									}, {
										field: 'runStatus',
										title: '运行状态',
										sortable: true,
										formatter: function (val, rec) {
											return val == 0 ? '暂停' : (val == 2 ? '执行中' : '恢复');
										}
										// }, {
										// 	field: 'beginTime',
										// 	title: '开始时间',
										// 	sortable: true,
										// 	formatter: function (val, rec) {
										// 		return val ? unescape(val) : '';
										// 	}
										// }, {
										// 	field: 'endTime',
										// 	title: '结束时间',
										// 	sortable: true,
										// 	formatter: function (val, rec) {
										// 		return val ? unescape(val) : '';
										// 	}
									}, {
										field: 'errorLog',
										title: '错误日志',
										sortable: true,
										formatter: function (val, rec) {
											return val ? unescape(val) : '';
										}
									}, {
										field: 'remark',
										title: '备注',
										sortable: true,
										formatter: function (val, rec) {
											return val ? unescape(val) : '';
										}
										// }, {
										// 	field: 'creator',
										// 	title: '创建人',
										// 	sortable: true,
										// 	formatter: function (val, rec) {
										// 		return val ? unescape(val) : '';
										// 	}
									}, {
										field: 'createTime',
										title: '创建时间',
										sortable: true,
										formatter: function (val, rec) {
											return val ? unescape(val) : '';
										}
									}]],
									toolbar: [
										{
											text: '增加',
											iconCls: 'icon-add',
											handler: function () {
												$('#fm').form('clear');
												$('#add').window('open');
											}
										},
										'-',
										{
											text: '编辑',
											iconCls: 'icon-edit',
											handler: function () {
												var row = $('#dg').datagrid(
													'getSelected');
												if (row) {
													$('#add').dialog('open').dialog(
														'center').dialog(
															'setTitle', '');
													$('#fm').form('load', row);
												}
											}
										},
										'-',
										{
											text: '删除',
											iconCls: 'icon-cancel',
											handler: function () {
												var row = $('#dg').datagrid(
													'getSelected');
												if (row) {
													$.messager.confirm('提示',
														'确定要删除吗?', function (r) {
															if (r) {
																del(row);
															}
														});
												}
											}
										},
										'-',
										{
											text: '运行',
											iconCls: 'icon-ok',
											handler: function () {
												var row = $('#dg').datagrid(
													'getSelected');
												if (row) {
													$.messager.confirm('提示',
														'确定要运行吗?', function (r) {
															if (r) {
																run(row);
															}
														});
												}
											}
										},
										'-',
										{
											text: '暂停',
											iconCls: 'icon-undo',
											handler: function () {
												var row = $('#dg').datagrid(
													'getSelected');
												if (row) {
													$.messager.confirm('提示',
														'确定要暂停吗?', function (r) {
															if (r) {
																pause(row);
															}
														});
												}
											}
										},
										'-',
										{
											text: '恢复',
											iconCls: 'icon-redo',
											handler: function () {
												var row = $('#dg').datagrid(
													'getSelected');
												if (row) {
													$.messager.confirm('提示',
														'确定要恢复吗?', function (r) {
															if (r) {
																resume(row);
															}
														});
												}
											}
										}],
									onLoadSuccess: function () {
									},
									onDblClickRow: function () {
										editrow();
									}
								});
							$('#dg').datagrid('enableFilter');
						}
					</script>
					<style scoped="scoped">
						.textbox {
							height: 20px;
							margin: 0;
							padding: 0 2px;
							box-sizing: content-box;
						}

						/*.table tr {
        height: 15px;
    }*/
					</style>

					<div class="query_criteria" id="query_criteria">
						<table id="dg"></table>


						<div id="add" class="easyui-window" closed="true" modal="true" title="用户信息"
							style="width: 500px; height: 450px; padding: 10px 20px">
							<form id="fm" class="ssec-form">
								<table class="table">
									<!-- <tr>
						<td>
							<div class="ssec-label">任务id：</div>
						</td>
						<td>
							<div class="ssec-text normal">
								<input id="jobId" name="jobId"
									class="easyui-validatebox textbox" data-options="required:true" />
							</div>
						</td>
					</tr> -->
									<tr>
										<td>
											<div class="ssec-label">执行类：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="jobId" name="jobId" type="hidden" />
												<input id="beanName" name="beanName" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">执行方法：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="methodName" name="methodName" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<!-- <tr>
						<td>
							<div class="ssec-label">参数：</div>
						</td>
						<td>
							<div class="ssec-text normal">
								<input id="params" name="params"
									class="easyui-validatebox textbox" data-options="required:true" />
							</div>
						</td>
					</tr> -->
									<tr>
										<td>
											<div class="ssec-label">表达式：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="cronExpression" name="cronExpression" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<!-- <tr>
						<td>
							<div class="ssec-label">启用禁用：</div>
						</td>
						<td>
							<div class="ssec-text normal">
								<input id="status" name="status"
									class="easyui-validatebox textbox" data-options="required:true" />
							</div>
						</td>
					</tr> -->
									<tr>
										<td>
											<div class="ssec-label">状态：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="status" name="status" class="easyui-combobox" data-options="required:true, 
												textField: 'label',valueField: 'value',data: [{
														label: '启用',
														value: '1'
													},{
														label: '禁用',
														value: '0'
													}]" />
											</div>
										</td>
									</tr>
									<!-- <tr>
						<td>
							<div class="ssec-label">开始时间：</div>
						</td>
						<td>
							<div class="ssec-text normal">
								<input id="beginTime" name="beginTime"
									class="easyui-validatebox textbox" data-options="required:true" />
							</div>
						</td>
					</tr>
					<tr>
						<td>
							<div class="ssec-label">结束时间：</div>
						</td>
						<td>
							<div class="ssec-text normal">
								<input id="endTime" name="endTime"
									class="easyui-validatebox textbox" data-options="required:true" />
							</div>
						</td>
					</tr> -->
									<!-- <tr>
						<td>
							<div class="ssec-label">错误日志：</div>
						</td>
						<td>
							<div class="ssec-text normal">
								<input id="errorLog" name="errorLog"
									class="easyui-validatebox textbox" data-options="required:true" />
							</div>
						</td>
					</tr> -->
									<tr>
										<td>
											<div class="ssec-label">备注：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="remark" name="remark" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<!-- <tr>
						<td>
							<div class="ssec-label">创建人：</div>
						</td>
						<td>
							<div class="ssec-text normal">
								<input id="creator" name="creator"
									class="easyui-validatebox textbox" data-options="required:true" />
							</div>
						</td>
					</tr>
					<tr>
						<td>
							<div class="ssec-label">创建时间：</div>
						</td>
						<td>
							<div class="ssec-text normal">
								<input id="createTime" name="createTime"
									class="easyui-validatebox textbox" data-options="required:true" />
							</div>
						</td>
					</tr> -->
								</table>
								<div style="padding: 5px; text-align: right;">
									<a class="easyui-linkbutton" onclick="save();" iconcls="icon-save">保存</a>
								</div>
							</form>
						</div>
					</div>
		</body>

		</html>